package utils

import "encoding/json"

type Rsp struct {
	Code int         `json:"code"`
	Data interface{} `json:"data"`
	Msg  string      `json:"msg"`
}

func Success(data interface{}) []byte {

	res := &Rsp{
		Code: 0,
		Data: data,
		Msg:  "success",
	}
	bytes, _ := json.Marshal(res)
	return bytes
}

func Fail(err error) []byte {

	res := &Rsp{
		Code: -1,
		Data: nil,
		Msg:  err.Error(),
	}
	bytes, _ := json.Marshal(res)
	return bytes
}
